package cn.com.miao.lynx.common.base.mapping;

import cn.com.miao.lynx.common.base.model.TreeModel;
import cn.com.miao.lynx.common.base.vo.BaseTreeVo;
import cn.com.miao.lynx.common.core.syntactic.OperatorKt;

import java.io.Serializable;
import java.util.List;

/**
 * TreeMapStructMapping
 *
 * @title: TreeMapStructMapping
 * @description:
 * @author: dengmiao
 * @create: 2019-12-31 14:48
 **/
public interface TreeMapStructMapping<E extends TreeModel<E, ID>, ID extends Serializable> extends BaseMapStructMapping<E, ID> {

    @Override
    default <T> T to(E source, final Class<T> clazz) {
        if (BaseTreeVo.class.equals(clazz)) {
            return (T) toTreeVo(source);
        }
        return null;
    }

    @Override
    default <T> List<T> to(List<E> source, final Class<T> clazz) {
        return OperatorKt.convert(source, tree -> to(tree, clazz));
    }

    BaseTreeVo toTreeVo(E source);

    List<BaseTreeVo> toTreeVo(List<E> source);
}
